package codingforgreat.lchot150;

public class Lc162 {
    public int findPeakElement(int[] nums) {
        if(nums.length == 1){
            return 0;
        }
        if(nums[0] > nums[1]){
            return 0;
        }
        if(nums[nums.length - 1] > nums[nums.length - 2]){
            return nums.length - 1;
        }
        int L = 1;
        int R = nums.length - 2;
        while(L < R){
            int mid = (L + R) / 2;
            if(nums[mid - 1] < nums[mid] && nums[mid + 1] < nums[mid]){
                return mid;
            }else if(nums[mid] < nums[mid + 1]){
                L = mid + 1;
            }else{
                R = mid - 1 ;
            }
        }
        return L;
    }
}
